package com.lanchetech.dao;
import com.lanchetech.entity.AdminPermission;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import com.lanchetech.entity.AdminRolePermission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AdminRolePermissionMapper {
    int insert(AdminRolePermission record);

    int insertSelective(AdminRolePermission record);

    int deleteByRoleId(@Param("roleId")Long roleId);

    @Select("select p.* from admin_role_permission a left join admin_permission p on p.id = a.permission_id where a.role_id = #{id}")
    List<AdminPermission> getAdminRolePermissionList(Long id);

    @Insert("<script> insert into admin_role_permission (role_id,permission_id) values\n" +
            "        <foreach collection=\"list\" item=\"item\" index=\"index\" separator=\",\">\n" +
            "            (#{roleId},#{item})\n" +
            "        </foreach>\n" +
            "</script>"
    )
    void insertAdminRolePermissions(List<Integer> list, Long roleId);

    List<AdminRolePermission> findAllByPermissionId(@Param("permissionId")Long permissionId);


}